import Axios from 'axios';

const instanceNormal = () => {
    let token = sessionStorage.getItem("token");
    let headers = token ? {
        "Authorization": sessionStorage.getItem("token")
    } : {};
    return Axios.create({
        headers
    });
}

/**
 * @template D
 * @typedef {import("axios").AxiosRequestConfig<D>} AxiosRequestConfig<D>
 */

/**
 * get 在config对象中指明params
 * @param {string} url
 * @param {AxiosRequestConfig} config
 * @returns
 */
const _get = (url, config) => {
    return new Promise((resolve, reject) => {
        instanceNormal()
            .get(url, config)
            .then(data => {
                // console.log(data);
                resolve(data.data);
            })
            .catch(err => {
                reject(err);
            });
    });
};

export default {
    _get
}
